package top.codedance.iotp.client.plugins.async.system;

import cd.io.netty.channel.ChannelHandlerContext;
import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.client.ClientApplication;
import top.codedance.iotp.common.executer.AsyncAbstractExecuter;
import top.codedance.iotp.common.entity.CommonEntity;
import org.apache.log4j.Logger;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SystemExecuterImpl extends AsyncAbstractExecuter {
    private static Logger logger = ClientApplication.getLogger(SystemExecuterImpl.class);
    public static ExecutorService pools = Executors.newCachedThreadPool();

    @Override
    public void exec(ChannelHandlerContext channelHandlerContext, CommonEntity commonEntity, String taskId) {
        super.exec(channelHandlerContext, commonEntity, taskId);
        final JSONObject request = this.getRequestBodyJSONObject();
        pools.submit(() -> SystemService.genOrGetInstance(SystemExecuterImpl.this).exec(request));
    }
}
